package com.redriver.hospitalsystem.systemgetway.exception;


import com.RedRiver.hospitalsystem.result.Result;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.MalformedJwtException;
import org.springframework.stereotype.Component;

import java.security.SignatureException;

@Component
public class GatewayException {
    @ExceptionHandler(Exception.class)
    public Result<?> exception(Exception e){
        return Result.getInstance().setMsg("出现异常").setCode(500);
    }

    @ExceptionHandler(ProException.class)
    public Result<?> exception(ProException e){
        return Result.getInstance().setMsg(e.getMessage()).setCode(e.getCode());
    }

    @ExceptionHandler(MalformedJwtException.class)
    public Result<?> exception(MalformedJwtException e){
        return Result.getInstance().setMsg("验签失败").setCode(405);
    }

    @ExceptionHandler(IllegalArgumentException.class)
    public Result<?> exception(IllegalArgumentException e){
        return Result.getInstance().setMsg("token不能为空").setCode(405);
    }

    @ExceptionHandler(SignatureException.class)
    public Result<?> exception(SignatureException e){
        return Result.getInstance().setMsg("验签失败").setCode(405);
    }

    @ExceptionHandler(ExpiredJwtException.class)
    public Result<?> exception(ExpiredJwtException e){
        return Result.getInstance().setMsg("token过期").setCode(405);
    }
}
